Skip to content

fix(opencode): use plural commands/ directory to match OpenCode convention#760

Open
fsilvaortiz wants to merge 3 commits intoFission-AI:mainfrom
fsilvaortiz:fix/748-opencode-commands-directory
Open

fix(opencode): use plural commands/ directory to match OpenCode convention#760
fsilvaortiz wants to merge 3 commits intoFission-AI:mainfrom
fsilvaortiz:fix/748-opencode-commands-directory

Conversation

@fsilvaortiz
Copy link

@fsilvaortiz fsilvaortiz commented Feb 25, 2026

Summary

  • OpenCode adapter path corrected from .opencode/command/ (singular) to .opencode/commands/ (plural) to match OpenCode's official directory convention
  • Legacy cleanup detects both opsx-*.md and openspec-*.md in old singular path (via string | string[] pattern support)
  • Auto-cleanup legacy artifacts in non-interactive mode (CI) instead of aborting with exit 1
  • Documentation, specs, and tests updated accordingly

Fixes #748.

Test plan

  • All 82 adapter tests pass (pnpm vitest run test/core/command-generation/adapters.test.ts)
  • All 88 legacy-cleanup tests pass (pnpm vitest run test/core/legacy-cleanup.test.ts)
  • All 42 init tests pass (pnpm vitest run test/core/init.test.ts)
  • Build succeeds (pnpm build)
  • Verify openspec init --tools opencode generates files at .opencode/commands/
  • Verify legacy cleanup detects old .opencode/command/opsx-*.md artifacts
  • Verify legacy cleanup detects old .opencode/command/openspec-*.md artifacts
  • Verify both patterns map to opencode tool ID (deduplicated)
  • Verify non-interactive init auto-cleans legacy artifacts without --force

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Store OpenCode commands in the correct plural directory and auto-migrate legacy artifacts during initialization (including non-interactive runs).
  • Documentation

    • Updated supported-tools reference to reflect the corrected OpenCode command path.
  • Tests

    • Added tests covering legacy detection, cleanup, and the updated command path behavior.
  • Chores

    • Added release notes/spec/config entries for the patch.

…vention

The OpenCode adapter was using `.opencode/command/` (singular) but OpenCode's
official documentation specifies `.opencode/commands/` (plural). This aligns
with every other adapter in the codebase. Legacy cleanup updated to detect
old singular-path artifacts. Fixes Fission-AI#748.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@fsilvaortiz fsilvaortiz requested a review from TabishB as a code owner February 25, 2026 19:04
@greptile-apps
Copy link

greptile-apps bot commented Feb 25, 2026

Greptile Summary

This PR corrects the OpenCode adapter to use the plural .opencode/commands/ directory path instead of the singular .opencode/command/, aligning with OpenCode's official convention and matching the pattern used by all other adapters in the codebase.

Key changes:

  • Adapter path corrected in src/core/command-generation/adapters/opencode.ts (line 20)
  • Legacy cleanup updated to detect old singular-path artifacts at .opencode/command/opsx-*.md
  • Documentation and tests updated to reflect the new path
  • Comprehensive spec-driven change documentation included

Quality notes:

  • The legacy cleanup pattern correctly uses opsx-*.md (not openspec-*.md) since OpenCode adapter always used the opsx- prefix from its introduction
  • All 82 adapter tests pass according to the PR description
  • Change follows established patterns across the codebase (all other adapters use plural directory names)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • Simple path correction with comprehensive test coverage and documentation. The change is a straightforward string replacement that aligns with established conventions. Legacy cleanup properly handles backward compatibility.
  • No files require special attention

Important Files Changed

Filename Overview
src/core/command-generation/adapters/opencode.ts Changed path from .opencode/command/ to .opencode/commands/ (plural) to match OpenCode convention
src/core/legacy-cleanup.ts Updated legacy pattern to detect old singular-path artifacts with opsx-*.md prefix
test/core/command-generation/adapters.test.ts Updated test assertion to match new plural commands/ directory path
docs/supported-tools.md Updated documentation table to reflect corrected .opencode/commands/ path

Last reviewed commit: c58d3c8


#### Scenario: Detect old singular-path OpenCode command files

- **WHEN** running legacy artifact detection on a project with files matching `.opencode/command/openspec-*.md` or `.opencode/command/opsx-*.md`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario says we detect both openspec-* and opsx-* in .opencode/command/, but the implementation currently only has opsx-*. Can we align code and spec here so behavior is clear?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aligned — LegacySlashCommandPattern.pattern now accepts string | string[], and the opencode entry uses both patterns: ['.opencode/command/opsx-*.md', '.opencode/command/openspec-*.md']. Added 6 tests covering detection and tool ID mapping for both prefixes.

'auggie': { type: 'files', pattern: '.augment/commands/openspec-*.md' },
'factory': { type: 'files', pattern: '.factory/commands/openspec-*.md' },
'opencode': { type: 'files', pattern: '.opencode/command/openspec-*.md' },
'opencode': { type: 'files', pattern: '.opencode/command/opsx-*.md' },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix on the directory rename. One compatibility gap: this only matches .opencode/command/opsx-*.md. Some older installs may still have .opencode/command/openspec-*.md. Can we detect both so those users are migrated too?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — same change as above. The opencode entry now detects both opsx-*.md and openspec-*.md in .opencode/command/. Both patterns map to the opencode tool ID, so legacy cleanup and tool re-detection work for either prefix. Verified with detectLegacyArtifacts and getToolsFromLegacyArtifacts.


#### Scenario: Clean up old OpenCode command files on init

- **WHEN** a user runs `openspec init` in a project with old `.opencode/command/` artifacts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also account for non-interactive openspec init here? Right now legacy artifacts cause init to exit unless --force is set. That could surprise existing /command users in CI. Either auto-handle this rename migration or call out the one-time --force requirement in release notes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — handleLegacyCleanup now auto-cleans in non-interactive mode instead of aborting with exit 1. Legacy slash commands are 100% OpenSpec-managed, and config file cleanup only removes markers (never deletes files), so auto-cleanup is safe without --force.

Added a test verifying that openspec init --tools opencode in non-interactive mode cleans up .opencode/command/ legacy files and generates new ones at .opencode/commands/. Spec updated with the new scenario.

… in CI

- Extend LegacySlashCommandPattern.pattern to accept string | string[]
- OpenCode legacy entry now detects both opsx-*.md and openspec-*.md
- Auto-cleanup legacy artifacts in non-interactive mode instead of
  aborting with exit 1 (safe: slash commands are OpenSpec-managed,
  config cleanup only removes markers)
- Add 7 tests (6 legacy detection + 1 non-interactive init)
- Update spec with array pattern support and auto-cleanup scenario

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2ece90 and 692244b.

📒 Files selected for processing (1)
  • openspec/changes/fix-opencode-commands-directory/tasks.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • openspec/changes/fix-opencode-commands-directory/tasks.md

📝 Walkthrough

Walkthrough

Updates OpenCode adapter to write commands to .opencode/commands/ (plural), adds legacy-detection for the old .opencode/command/ patterns, enables automatic cleanup in non-interactive init, and updates tests, docs, and spec artifacts to reflect the change.

Changes

Cohort / File(s) Summary
Changeset & Docs
\.changeset/fix-opencode-commands-directory.md, docs/supported-tools.md
Adds patch changeset and updates documentation to reference .opencode/commands/opsx-<id>.md.
OpenCode Adapter
src/core/command-generation/adapters/opencode.ts
getFilePath now returns paths under .opencode/commands/ (plural) instead of .opencode/command/.
Legacy Cleanup & Init
src/core/legacy-cleanup.ts, src/core/init.ts
Allows legacy pattern to be `string
Tests — Adapters
test/core/command-generation/adapters.test.ts
Updated assertion to expect .opencode/commands/opsx-explore.md.
Tests — Init & Legacy Cleanup
test/core/init.test.ts, test/core/legacy-cleanup.test.ts
Adds tests that detect and cleanup .opencode/command/opsx-* and .opencode/command/openspec-* legacy files and verify migration to .opencode/commands/.
OpenSpec Change Docs & Spec
openspec/changes/fix-opencode-commands-directory/...
Adds proposal, design, spec, tasks, and openspec meta for the path migration and legacy-cleanup behavior.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Init as InitCommand
participant Legacy as LegacyCleanup
participant FS as FileSystem
participant Adapter as OpenCodeAdapter
Init->>Legacy: run legacy detection (non-interactive or --force)
Legacy->>FS: glob for legacy patterns (.opencode/command/*)
FS-->>Legacy: list of legacy files
alt legacy files found
Legacy->>FS: remove legacy files
Init->>Adapter: generate commands
Adapter->>FS: write to .opencode/commands/opsx-*.md
FS-->>Init: confirm creation
else no legacy
Init->>Adapter: generate commands (normal flow)
Adapter->>FS: write to .opencode/commands/opsx-*.md
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • TabishB

Poem

🐰 I hopped from command to commands with cheer,
Files rearranged, the path now clear,
Old crumbs cleaned up, new doors swing wide,
.opencode/commands/ is where we now hide,
A tiny rabbit dance for code, far and near.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: updating the OpenCode adapter to use the plural 'commands/' directory to align with OpenCode's official convention, directly addressing issue #748.
Linked Issues check ✅ Passed The PR successfully addresses all primary coding objectives from issue #748: changes the adapter path to the plural form (.opencode/commands/), implements backward compatibility via legacy cleanup supporting both opsx-* and openspec-* patterns, updates tests and documentation, and enables non-interactive auto-cleanup.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving issue #748: adapter path update, legacy pattern support, backward compatibility handling, non-interactive cleanup, and related test/documentation updates. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
openspec/changes/fix-opencode-commands-directory/tasks.md (1)

7-7: Minor discrepancy: Task description doesn't fully reflect the implementation.

The task description says to change the pattern from openspec-*.md to opsx-*.md, but the actual implementation in src/core/legacy-cleanup.ts supports both patterns as an array: ['.opencode/command/opsx-*.md', '.opencode/command/openspec-*.md'].

Consider updating this task description to accurately reflect that both legacy prefixes are now supported:

-- [x] 2.1 Update `src/core/legacy-cleanup.ts`: change the `'opencode'` entry in `LEGACY_SLASH_COMMAND_PATHS` from `'.opencode/command/openspec-*.md'` to `'.opencode/command/opsx-*.md'` to detect old singular-path artifacts with the current `opsx-*` prefix
++ [x] 2.1 Update `src/core/legacy-cleanup.ts`: update the `'opencode'` entry in `LEGACY_SLASH_COMMAND_PATHS` to detect both `opsx-*.md` and `openspec-*.md` patterns at `.opencode/command/` for backward compatibility
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@openspec/changes/fix-opencode-commands-directory/tasks.md` at line 7, Update
the task description in tasks.md to match the implementation: state that
LEGACY_SLASH_COMMAND_PATHS in src/core/legacy-cleanup.ts now supports both
legacy patterns (the opsx-* prefix and the openspec-* prefix) rather than only
replacing openspec-*.md with opsx-*.md, so reword the checklist item to
explicitly mention both opsx-* and openspec-* patterns are supported.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@openspec/changes/fix-opencode-commands-directory/tasks.md`:
- Line 7: Update the task description in tasks.md to match the implementation:
state that LEGACY_SLASH_COMMAND_PATHS in src/core/legacy-cleanup.ts now supports
both legacy patterns (the opsx-* prefix and the openspec-* prefix) rather than
only replacing openspec-*.md with opsx-*.md, so reword the checklist item to
explicitly mention both opsx-* and openspec-* patterns are supported.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7d1860 and f2ece90.

📒 Files selected for processing (13)
  • .changeset/fix-opencode-commands-directory.md
  • docs/supported-tools.md
  • openspec/changes/fix-opencode-commands-directory/.openspec.yaml
  • openspec/changes/fix-opencode-commands-directory/design.md
  • openspec/changes/fix-opencode-commands-directory/proposal.md
  • openspec/changes/fix-opencode-commands-directory/specs/command-generation/spec.md
  • openspec/changes/fix-opencode-commands-directory/tasks.md
  • src/core/command-generation/adapters/opencode.ts
  • src/core/init.ts
  • src/core/legacy-cleanup.ts
  • test/core/command-generation/adapters.test.ts
  • test/core/init.test.ts
  • test/core/legacy-cleanup.test.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCode command directory: command/ vs commands/

2 participants